package com.kaishengit.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import com.kaishengit.pojo.Operator;
import com.kaishengit.service.OperatorService;


@Controller
public class OperatorController {
	private OperatorService operatorService;
	
	
	@RequestMapping("/operatorList")
	public String findAll(Model model){
		List<Operator> operatorList = operatorService.findAll();
		model.addAttribute("operatorList", operatorList);
		return "system";
	}
	@RequestMapping("/addOperator")
	public String add(Operator operator){
		operatorService.add(operator);
			return "redirect:/operatorList";
		
	}
	@RequestMapping("/delOperator{id}")
	public String del( @PathVariable String id){
		operatorService.del(id);
		return "redirect:/operatorList";
	}
	
	@RequestMapping("/editOperator")
	public String edit(Operator ope,String newpwd){
		Operator operator = operatorService.findByNameByPassword(ope);
		operator.setPassword(newpwd);
		operatorService.edit(operator);
		return "login";
	}
	@Autowired
	public void setOperatorService(OperatorService operatorService) {
		this.operatorService = operatorService;
	}
	
	
	
}
